package mapper

import (
	"gin-epg/internal/app/dao"
	"gin-epg/internal/app/entity"
)

// CreateEpgProgramTplSeg 创建一个新的 EpgProgramTplSeg
func CreateEpgProgramTplSeg(epgProgramTplSeg *entity.EpgProgramTplSeg) (err error) {
	if err = dao.SqlSession.Create(epgProgramTplSeg).Error; err != nil {
		return err
	}
	return
}

/*
* 获取 EpgProgramTplSeg 集合
 */
func GetAllEpgProgramTplSeg() (epgProgramTplSegList []*entity.EpgProgramTplSeg, err error) {
	if err := dao.SqlSession.Find(&epgProgramTplSegList).Error; err != nil {
		return nil, err
	}
	return
}

/*
* 根据 id 删除 EpgProgramTplSeg
 */
func DeleteEpgProgramTplSegById(id string) (err error) {
	err = dao.SqlSession.Where("id=?", id).Delete(&entity.EpgProgramTplSeg{}).Error
	return
}

/*
* 根据 id 查询 EpgProgramTplSeg
 */
func GetEpgProgramTplSegById(id string) (epgProgramTplSeg *entity.EpgProgramTplSeg, err error) {
	// 初始化 epgProgramTplSeg 变量
	epgProgramTplSeg = new(entity.EpgProgramTplSeg)

	// 执行查询
	if err = dao.SqlSession.Where("id=?", id).First(epgProgramTplSeg).Error; err != nil {
		return nil, err
	}
	return epgProgramTplSeg, nil
}

/*
* 更新 EpgProgramTplSeg 信息
 */
func UpdateEpgProgramTplSeg(epgProgramTplSeg *entity.EpgProgramTplSeg) (err error) {
	err = dao.SqlSession.Save(epgProgramTplSeg).Error
	return
}
